import 'package:flutter/material.dart';

 import '../view/home.dart';
import '../view/login_view.dart';
import '../view/board.dart';

//final routes = {
//  // '/': (context, {arguments}) => Homepage(),
//  '/': (context, {arguments}) => MyHomePage(),
//};
//// 固定写法
//var onGenerateRoute = (RouteSettings  settings){
//  // 统一处理RouteSettings = {_Type} RouteSettings
//  final name = settings.name;
//  final pageContentBuilder = routes[name];
//  Route route;
//  if (pageContentBuilder != null) {
//    if (settings.arguments != null) {
//      route = MaterialPageRoute(
//          builder: (context) =>
//              pageContentBuilder(context, arguments: settings.arguments));
//      return route;
//    } else {
//      route =
//          MaterialPageRoute(builder: (context) => pageContentBuilder(context));
//      return route;
//    }
//    }
//};

class Routes extends NavigatorObserver  {
  static final Map<String, WidgetBuilder> routes = {
    // "/": (context, {arguments}) => MyHomePage(),
    // "/" : (context, {arguments}) => Board(),
    "/" : (context, {arguments}) => Board(),
  };
  static RouteFactory get onGenerateRoute => (RouteSettings  settings){
    final name = settings.name;
    final pageContentBuilder = routes[name];
    if (pageContentBuilder != null) {
      if (settings.arguments != null) {
        return MaterialPageRoute(
          builder: (context) =>
          pageContentBuilder(context),
          settings:RouteSettings(arguments:settings.arguments)
        );
  } else {
        return MaterialPageRoute(
            builder: (context) => pageContentBuilder(context));
      }
    }
  };
}

/*
* 路由监听类*/
class RouterLister extends NavigatorObserver{
  @override
  // push 路由监听
  void didPush(Route route, Route? previousRoute) {
    // TODO: implement didPush
    super.didPush(route, previousRoute);
  }
  @override
  void didPop(Route route, Route? previousRoute) {
    // TODO: implement didPop
    super.didPop(route, previousRoute);
  }
  @override
  void didReplace({Route? newRoute, Route? oldRoute}) {
    // TODO: implement didReplace
    super.didReplace();
  }
  @override
  void didRemove(Route route, Route? previousRoute) {
    // TODO: implement didRemove
    super.didRemove(route, previousRoute);
  }
}


